package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行DQL语句--SELECT
 */
public class JDBCDemo5 {
    public static void main(String[] args) throws Exception {
        //需求：查询teacher表中每个老师的id，name，salary，title
        Connection conn = DBUtil.getConnection();  //获取数据库连接
        Statement state = conn.createStatement();  //创建Statement对象
        String sql = "SELECT id,name,salary,title FROM teacher";   //准备SQL语句
        ResultSet rs =  state.executeQuery(sql);  //执行SQL语句，返回结果集
        while (rs.next()){
            int id = rs.getInt("id");
            String name = rs.getString("name");
            double salary = rs.getDouble("salary");
            String title = rs.getString("title");
            System.out.println(id+"--"+name+"--"+salary+"--"+title);
        }
        conn.close();
    }
}
